<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<title>问题池列表(管理员端)</title>

<%@include file="/WEB-INF/views/commons/common.jsp" %>

<link rel="stylesheet" type="text/css" href="${base_href}/static/ui-frame/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="${base_href}/static/ui-frame/jquery-easyui/1.4.3/themes/metro/easyui.css">
<link rel="stylesheet" type="text/css" href="${base_href}/static/ui-frame/bootstrap-dialog3/css/bootstrap-dialog.css">
<link rel="stylesheet" type="text/css" href="${base_href}/static/ui-frame/validation-engine/validationEngine.jquery.css">
<link rel="stylesheet" type="text/css" href="${base_href}/static/css/search-theme.css">

</head>
<body  data-grid="easyui">
	<div class="path"><span class="right-index">&gt;</span>  现在的位置：问题池列表(管理员端)</div>
<div class="tab-content">
	<div class="fold_ex">
		<h2 class="title-h2">
			<span style="width:100%;">
				<button type="button" class="btn search-btn" data-method="insert"><i class="fa fa-plus"></i>&nbsp;录入题目&nbsp;</button>
				<button type="button" class="btn search-btn" data-method="edit"><i class="fa fa-edit"></i>&nbsp;编辑&nbsp;</button>
				<button type="button" class="btn search-btn" data-method="remove"><i class="fa fa-remove"></i>&nbsp;删除&nbsp;</button>
				<button type="button" class="btn search-btn" data-method="publish"><i class="fa fa-exchange"></i>&nbsp;发布&nbsp;</button>
				<button type="button" class="btn search-btn" data-method="exportStatics"><i class="fa fa-sign-out"></i>&nbsp;导出今日统计&nbsp;</button>
				<button type="button" class="btn search-btn" data-method="checkLog"><i class="fa fa-edit"></i>&nbsp;查看日志&nbsp;</button>
				<button type="button" class="btn search-btn" data-method="appoint"><i class="fa fa-exchange"></i>&nbsp;指派&nbsp;</button>
				<select name="appointUser" class="form-control" style="margin-left: 300px;width:30%;">
					<option value="" selected="selected">请选择</option>
					<c:forEach items="${users}" var="state">
						<option value="${state.account}">${state.userName}</option>
					</c:forEach> 
				</select>
			</span>
			<form id="uploadForm" enctype="multipart/form-data" method="post">
				<input id="upfile" type="file" name="upfile" >
				<input type="button" class="btn search-btn" value="导入" id="importQues" name="btn">
			</form>
			<a href="javascript:void(0);" class="hide-next-btn">收起</a>
		</h2>
		
		<div>
		<form action="#">
			<table class="search-table container">
				<tr>
					<td class="text-right col-xs-2">问题详情</td>
					<td class="col-xs-4">
						<input type="text" class="form-control" name="question" value="" />
					</td>
					<td class="text-right col-xs-2">认领老师</td>
					<td class="col-xs-4">
						<input type="text" class="form-control" name=teacheName value="" />
					</td>
				</tr>
				<tr>
					<td class="text-right col-xs-2">提问时间起</td>
					<td class="col-xs-4"><input type="text" class="form-control"
						id="askStartTime" name="askStartTime" value=""
						onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'askEndTime\')}'});"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" />
					</td>
					<td class="text-right col-xs-2">提问时间止</td>
					<td class="col-xs-4"><input type="text" class="form-control"
						id="askEndTime" name="askEndTime" value=""
						onFocus="WdatePicker({minDate: '#F{$dp.$D(\'askStartTime\')}'});"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" />
					</td>
				</tr>
				
				<tr>
					<td class="text-right col-xs-2">答疑结束时间起</td>
					<td class="col-xs-4"><input type="text" class="form-control"
						id="answerStartTime" name="answerStartTime" value=""
						onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'answerEndTime\')}'});"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" />
					</td>
					<td class="text-right col-xs-2">答疑结束时间止</td>
					<td class="col-xs-4"><input type="text" class="form-control"
						id="answerEndTime" name="answerEndTime" value=""
						onFocus="WdatePicker({minDate: '#F{$dp.$D(\'answerStartTime\')}'});"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="readonly" />
					</td>
				</tr>
				
				<tr>
					<td class="text-right col-xs-2">问题状态</td>
					<td class="col-xs-4">
						<select name="quesType" class="form-control">
							<option value="" selected="selected">请选择</option>
							 <c:forEach items="${quesTypes}" var="state">
								<option value="${state.code}">${state.value}</option>
							</c:forEach> 
						</select>
					</td>
					<td class="text-right col-xs-2">问题来源</td>
					<td class="col-xs-4">
						<select name="questionSource" class="form-control">
							<option value="" selected="selected">请选择</option>
							 <c:forEach items="${questionSources}" var="state">
								<option value="${state.code}">${state.value}</option>
							</c:forEach> 
						</select>
					</td>
				</tr>
				<tr>
					<td class="text-right col-xs-2">考试类别</td>
					<td class="col-xs-4">
						<select name="major" class="form-control">
							<option value="" selected="selected">请选择</option>
							 <c:forEach items="${quesBookClasses}" var="state">
								<option value="${state.code}">${state.value}</option>
							</c:forEach> 
						</select>
					</td>
					<td class="text-right col-xs-2"></td>
					<td class="col-xs-4">
					</td>
				</tr>
				<tr>
					<td class="text-right col-xs-2"></td>
					<td class="text-right">
						<button type="button" class="btn search-btn" data-method="search"><i class="fa fa-search"></i>&nbsp;查询&nbsp;</button>
						<button type="button" class="btn search-btn" data-method="clear"><i class="fa fa-trash"></i>&nbsp;清空&nbsp;</button>
					</td>
				</tr>
			</table>
		</form>
		</div>

		<hr class="search-line"/>
		<table class="easyui-datagrid" >
			<thead>
				<tr>
					<th data-options="field:'id',checkbox:true">选择</th>
					<th data-options="field:'questionSource',width:50,align:'center'">问题来源</th>
					<th data-options="field:'major',width:50,align:'center'">考试类别</th>
					<th data-options="field:'questionDescribe',width:150,align:'center'">问题详情</th>
					<th data-options="field:'quesTime',width:50,align:'center'">提问时间</th>
					<th data-options="field:'claimUserName',width:50,align:'center'">认领教师</th>
					<th data-options="field:'quesDiffLevel',width:30,align:'center'">难度</th>
					<th data-options="field:'quesType',width:30,align:'center'">问题状态</th>
				</tr>
			</thead>
		</table>
	</div>
</div>

<script type="text/javascript" src="${base_href}/static/ui-frame/jquery/1.11.3/jquery.js"></script>


<script type="text/javascript" src="${base_href}/static/ui-frame/iframe-auto-height/jquery.autoheight.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/bootstrap/3.3.5/js/bootstrap.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/bootstrap-dialog3/js/bootstrap-dialog.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/jquery-easyui/1.4.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/jquery-easyui/1.4.3/easyui.util.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/validation-engine/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/validation-engine/jquery.validationEngine.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${base_href}/static/ui-frame/webuploader/jquery-form.js"></script>

<script type="text/javascript" src="${base_href}/static/ui-frame/requirejs/2.2.0/require.js"></script>

<script type="text/javascript">
requirejs.config({
    baseUrl: '<c:url value="/static/"/>',
    paths: {
        Grid: 'component/grid/js/ms-grid',
    },
    config: {
    	'Grid': { contextPath: '<c:url value="/"/>' },
    }
});


require(['Grid'], function(Grid) {
	
	Grid.columns({
		questionDescribe: {
			formatter: function(value, row, index) {
				var v = value == null ? "" : $('<div/>').text(value).html();
				return "<a href='javaScript:void(0);' onclick=\"grid.questionDescribe(event, " + index + ")\" class='grid-button' plain='true' title='"+ v +"'><div>" +  v + "</div></a>";
			},
			event: function(event, index) {
				var row = this.grid.datagrid('getRows')[index];
				var param = {quesId: row.id};
				
				var url = basePath + "/adminQuesList/openReadPage.html?" + $.param(param);
				var screenLocation = "width=960px,height=960,top=0,left=0,menubar=yes,resizable=yes,scrollbars =yes";
				this.windowOpen(url, "详细信息",screenLocation); //打开题目只读页面
				event.stopPropagation();
			}
		},
		quesDiffLevel:{
			formatter: function(value, row, index) {
				var vv ;
				if(value == 1){
					vv = "简单";
				}else if(value == 2){
					vv = "一般";
				}else if(value == 3){
					vv = "困难";
				}
				return "<span>" + vv + "</span>"
			}
		}
		,
		quesType:{
			formatter: function(value, row, index) {
				var vv ;
				if(value == 1){
					vv = "未认领";
				}else if(value == 2){
					vv = "认领中";
				}else if(value == 3){
					vv = "已认领";
				}else if(value == 4){
					vv = "已解决";
				}else if(value == 5){
					vv = "已发布";
				}else if(value == 6){
					vv = "已完成";
				}else if(value == 0){
					vv = "待审核";
				}
				return "<span>" + vv + "</span>"
			}
		}
	});
	Grid.methods({
		insert:function(){
			var url = basePath + "/quesCollection/openQuesCollectionPage.html";
			var screenLocation = "width=960px,height=960,top=0,left=0,menubar=yes,resizable=yes,scrollbars =yes";
			this.windowOpen(url, "详细信息",screenLocation);
		},
		edit:function(){
			var _checked = this.grid.datagrid('getChecked');
			if (_checked.length == 1) {
				var param = {quesId: _checked[0].id};
				var url = basePath + "/adminQuesList/openEditPage.html?" + $.param(param);
				var screenLocation = "width=960px,height=960,top=0,left=0,menubar=yes,resizable=yes,scrollbars =yes";
				this.windowOpen(url, "详细信息",screenLocation);
			}else{
				BootstrapDialog.alert("请选择一条题目信息!");
			}
		},
		appoint:function(){
			var _checked = this.grid.datagrid('getChecked');
			if (_checked.length == 1) {
				var that = this;
				var userAccount = $("select[name='appointUser']").val();
				var userName = $("select[name='appointUser']").find("option:selected").text()
				if(userAccount != '' && userAccount != null){
					var param = {quesId: _checked[0].id,userAccount:userAccount,userName:userName};
					$.ajax({
						url:  basePath+"/adminQuesList/appoint.json?" + $.param(param),
						type: "get",
						async: false, //不可异步,必须同步
						dataType:"json",
						success: function(r){ 
							that.grid.datagrid('reload', that.queryParam());
							BootstrapDialog.alert({title: "提示", message:"指定教师成功。"});
							}
					})
					.fail(function() { BootstrapDialog.alert({title: "提示", message:"指定教师失败，请联系管理员。"}); })
				}else{
					BootstrapDialog.alert("请选择一位教师!");
				}
			}else{
				BootstrapDialog.alert("请选择一条题目信息!");
			}
		},
		remove:function(){
			var _checked = this.grid.datagrid('getChecked');
			if(_checked.length >= 1){
				var that = this;
				var ids =new Array();
				for(var k=0;k<_checked.length;k++){
					ids.push(_checked[k].id);
				}
				$.ajax({
					url:  basePath+"/adminQuesList/deletes.json?",
					type: "post",
					async: false, //不可异步,必须同步
					data:{ids: ids},
					traditional: true,
					dataType:"json",
					success: function(r){ 
						that.grid.datagrid('reload', that.queryParam());
						BootstrapDialog.alert({title: "提示", message:"删除数据成功。"});
						}
				})
				.fail(function() { BootstrapDialog.alert({title: "提示", message:"删除数据失败，请联系管理员。"}); })
			}else{
				BootstrapDialog.alert("请选择至少一条题目信息!");
			}
		},
		publish:function(){
			var _checked = this.grid.datagrid('getChecked');
			if(_checked.length >= 1){
				var that = this;
				var ids =new Array();
				for(var k=0;k<_checked.length;k++){
					if(_checked[k].quesType != 4){
						BootstrapDialog.alert("只能发布已解决状态的题目!");
						return;
					}
					ids.push(_checked[k].id);
				}
				$.ajax({
					url:  basePath+"/adminQuesList/publish.json?",
					type: "post",
					async: false, //不可异步,必须同步
					data:{ids: ids},
					traditional: true,
					dataType:"json",
					success: function(r){ 
						that.grid.datagrid('reload', that.queryParam());
						BootstrapDialog.alert({title: "提示", message:"发布题目成功。"});
						}
				})
				.fail(function() { BootstrapDialog.alert({title: "提示", message:"发布题目失败，请联系管理员。"}); })
			}else{
				BootstrapDialog.alert("请选择至少一条题目信息!");
			}
		},
		exportStatics:function(){
			/* 下载文件工具函数 */
			var iframe;
			var url = basePath+"/adminQuesList/download";
			if (iframe) {
				iframe.src = url;
			}
			else {
				iframe = document.createElement('iframe');
				iframe.src = url;
				iframe.style.display = "none";
				document.body.appendChild(iframe);
			}
		},
		checkLog:function(){
			var _checked = this.grid.datagrid('getChecked');
			if (_checked.length == 1) {
				var param = {quesId: _checked[0].id};
				var url = basePath + "/questionLog/quesLogPage.html?" + $.param(param);
				var screenLocation = "width=960px,height=960,top=0,left=0,menubar=yes,resizable=yes,scrollbars =yes";
				this.windowOpen(url, "详细信息",screenLocation);
			}else{
				BootstrapDialog.alert("请选择一条题目信息!");
			}
		}
		
	})
	
	$(function() {
		$('.easyui-datagrid').datagrid({
			rowStyler:function(index,row){
				if (row.quesType < 4 && 12 < row.quesTimeLong){
					return 'background-color:pink;font-weight:bold;';
				}
				if(row.quesType == 5){
					return 'background-color:#93f193;font-weight:bold;';
				}
			}
		});
		
		$("#importQues").click(function(){
			var fileDir = $("#upfile").val();
			var suffix = fileDir.substr(fileDir.lastIndexOf("."));
			if("" == fileDir){
				BootstrapDialog.alert("选择需要导入的Excel文件！");
				return false;
			}
			if(".xls" != suffix && ".xlsx" != suffix ){
				BootstrapDialog.alert("选择Excel格式的文件导入");
				return false;
			}
					
			$('#uploadForm').ajaxSubmit({
				url:basePath+'/adminQuesList/importExcel',
				data:$('#uploadForm').serialize(),
				dataType: 'text',
				success: function () {
					BootstrapDialog.alert("导入成功");
				},
				error: function (error) {
					BootstrapDialog.alert(error);
				}
			});
		});
		window.grid = Grid.events();
	})
}) 
</script>


</body>
</html>
